package it.gtd.swimpool.controller.resources;

import it.gtd.swimpool.model.business.AdministrationManager;
import it.gtd.swimpool.model.entity.Administrator;
import it.gtd.swimpool.model.entity.User;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.*;

@Stateless
@Path("/")
public class AdministratorResource extends SecuredResource {
    @PersistenceContext
    private EntityManager entityManager;

    @EJB
    private AdministrationManager administrationManager;


    @PUT
    @Path("/admins/{id}")
    public void promoteUser(
            @CookieParam(Cookie.SESSION_ID) String sessionId,
            @PathParam("id") int id
    ) {
        checkAdministrator(sessionId);

        User userToBePromoted = entityManager.find(User.class, id);

        administrationManager.promote(userToBePromoted);
    }
}
